package com.simoniu.mp.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Data;
import org.apache.ibatis.type.JdbcType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity
@TypeDef(name = "json", typeClass = JsonStringType.class)
@TableName(autoResultMap = true)

public class Users implements Serializable,Cloneable {

    //自增策略
    /*
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) //auto_increment类型
    @TableId(type = IdType.AUTO)
    */

    //MyBatis-Plus主键策略
    /*
    @Id
    @TableId(type = IdType.ASSIGN_ID)
    private Long uid;
    */

    //主键是字符串类型
    /*
    @Id
    @TableId(type = IdType.ASSIGN_UUID)
    private String uid;
    */

    //使用自定义的输入策略
    /*
    @Id
    @TableId(type = IdType.INPUT)
    private String uid;
    */

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) //auto_increment类型
    @TableId(type = IdType.AUTO)

    private Integer uid;
    private String username;

    @Column(length = 64)
    //@TableField(value = "pass")
    private String password;
    private String gender;
    private String email;
    private String address;

    //实体类使用下划线，保持和数据库字段一致。
    /*
    @TableField(fill = FieldFill.INSERT,value = "create_time")
    @Column(name="create_time")
    private Date create_time;

    @TableField(fill = FieldFill.INSERT_UPDATE,value="update_time")
    @Column(name="update_time")
    private Date update_time;
    */

    //数据库字段也使用驼峰标识。
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @TableLogic
    @TableField(fill = FieldFill.INSERT)
    private Integer deleted;

    //把用户自定义的类型映射为MySQL的json字段，添加hibernate-type-52依赖
    @TableField(jdbcType = JdbcType.BLOB, typeHandler = FastjsonTypeHandler.class)
    @Type(type = "json")
    @Column(columnDefinition = "json" )
    private Description description;

    @Transient
    @TableField(exist = false)
    private String validateCode;
}
